package com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.insurance;

import com.bmps.springcloud.insuredmicroservice.config.accept.ProductConfig;
import com.bmps.springcloud.insuredmicroservice.constant.accept.AcceptConstant;
import com.bmps.springcloud.insuredmicroservice.constant.accept.UnderWriteConstant;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.AcceptRequestDataModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.InsurantModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.ProductModel;
import com.bmps.springcloud.insuredmicroservice.model.underwrite.InsuredModel;
import com.bmps.springcloud.insuredmicroservice.repository.underwrite.coresystem.InsuredCoreRepository;
import com.bmps.springcloud.insuredmicroservice.util.accept.AcceptUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * description:
 * 金保鸿利
 *
 * @author jackdaw
 * @date 2020-06-12 11:43
 */
public class Lbp030InsuranceStrategy implements InsuranceStrategy {
    @Override
    public InsuredModel checkInsuredRolesByRiskCode(AcceptRequestDataModel acceptRequestDataModel, InsuredCoreRepository insuredCoreRepository, ProductModel productModel, ProductConfig productConfig) {
        //被保人信息
        List<InsurantModel> insurantModelList = acceptRequestDataModel.getRequest().getCustInfo().getInsurants().getInsurant();
        InsurantModel insurantModel = AcceptUtil.getInsurantModelBySeq(productModel.getProdInsSeq(), insurantModelList);
        //1.校验投保人和被保人的关系
        if (!(productConfig.getRelationList().contains(insurantModel.getRelToApp()))) {
            return AcceptUtil.getInsuredResponse(UnderWriteConstant.UNDER_WRITE_FIAL_CODE,
                    UnderWriteConstant.UNDER_WRITE_NUGG0007_MESSAGE);
        }

        //2.职业类别1-4类投保
        if (!AcceptConstant.OCCUPATION_ONE_TO_FOUR.contains(insurantModel.getOccupationType())) {
            return AcceptUtil.getInsuredResponse(UnderWriteConstant.UNDER_WRITE_FIAL_CODE, String.format(UnderWriteConstant.UNDER_WRITE_NPGG0016_MESSAGE, insurantModel.getOccupationType()));
        }
        //3.被保人健康告知
        if (StringUtils.equals(AcceptConstant.STRING_Y, insurantModel.getInsInform())) {
            return AcceptUtil.getInsuredResponse(UnderWriteConstant.UNDER_WRITE_UNDEFINED,
                    String.format(UnderWriteConstant.UNDER_WRITE_INS_INFORM, insurantModel.getName()));
        }
        //4.被保人理赔标识
        if (insurantModel.getClaimFlag() > 0) {
            return AcceptUtil.getInsuredResponse(UnderWriteConstant.UNDER_WRITE_NUGG0027,
                    String.format(UnderWriteConstant.UNDER_WRITE_NUGG0027_MESSAGE, insurantModel.getName()));
        }

        //5.黑名单
        if (insurantModel.getBlackListFlag() > 0) {
            return AcceptUtil.getInsuredResponse(UnderWriteConstant.UNDER_WRITE_NUGG0031,
                    String.format(UnderWriteConstant.UNDER_WRITE_NUGG0031_MESSAGE, insurantModel.getName()));
        }

        return AcceptUtil.getInsuredResponse(AcceptConstant.RESULT_SUCCESS_CODE, AcceptConstant.RESULT_SUCCESS_MESSAGE);
    }
}
